import 'package:example_app/annotations/route_annot.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:example_app/mapper/home_data_mapper.dart';
import 'package:example_app/model/banner_model.dart';
import 'package:example_app/widgets/load_builder.dart';

import 'logic.dart';

@ARoute(name: "main", path: "/main", description: "主页面")
class AppHomePage extends StatefulWidget {
  const AppHomePage({Key? key}) : super(key: key);

  @override
  State<AppHomePage> createState() => _AppHomePageState();
}

class _AppHomePageState extends State<AppHomePage> {
  final HomeLogic logic = Get.put(HomeLogic());
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("示例代码"),
      ),
      body: LoadBuilder<HomeDataMapper>(
        doRetry: logic.loadHomeData,
        data: logic.homeData,
        builder: (_, data) {
          return CustomScrollView(
            slivers: [
              // SliverToBoxAdapter(child: buildBanner(data.bannerData)),
              SliverGrid.count(
                crossAxisCount: 3,
                children: data.siteData
                    .map<Widget>((e) => Card(
                          child: Text("  ${e.name}   "),
                        ))
                    .toList(),
              ),
              SliverList(
                delegate: SliverChildBuilderDelegate((ctx, index) {
                  return Card(
                    child: Text(" ${data.articleData[index].title}"),
                  );
                }, childCount: data.articleData.length),
              )
            ],
          );
        },
      ),
    );
  }

  // Widget buildBanner(List<BannerData> data) {
  //   return AspectRatio(
  //     aspectRatio: 1.5,
  //     child: BannerSwiper(
  //       length: data.length,
  //       getwidget: (index){
  //         return Image.network(data[index].imagePath);
  //       }, width: 108, height: 54,
  //     ),
  //   );
  // }
}
